#!/bin/bash

if [ -z "$1" ]; then
	echo "Error: Usage is $0 <GIT_COMMAND>"
	exit 1	
fi

NUM_PARALLEL_THREADS=8

CWD=$(pwd);
ls -1d */.git | xargs -I FIL dirname FIL | \
while read line; do \
 ((i=i%NUM_PARALLEL_THREADS)); ((i++==0)) && wait
 echo "[thread $i] Processing: $line";\
 cd $CWD/$line; \
 git "$@" & \
done;

# Wait for all children processes to end:
wait

